<?php
include("model/employees.php");
class employeesController{
	
	function indexAction(){
		$smarty = $_SESSION['smarty'];
		
		$list_employees_box = $this->getListEmployeeBox();
		$smarty->assign("list_employees_box",$list_employees_box);
		
		$content = $smarty->fetch("employees/employees.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");
	}
	
	function getListEmployeeBox(){
		$smarty 	= $_SESSION['smarty'];
		$employee_obj 	= new employees();
		$employeeList	= $employee_obj->getEmployeesList();		
		$smarty->assign("employeeList", $employeeList);
		$html 		= $smarty->fetch("employees/employees_list.html");
		return $html;
	}
	
	function insertAction(){
		$employees_obj 	= new employees();
		$data 			= array();
		$data['emp_name'] 	= $_REQUEST['emp_name'];
		$data['emp_password'] 	= $_REQUEST['emp_password'];
		$data['emp_address']    = $_REQUEST['emp_address'];
		$data['emp_phone'] 		= $_REQUEST['emp_phone'];
		
		$result = $employees_obj->insertAEmployee($data);
		if ($result == 1)
			$msg = "insert successfully";
		else if ($result == -1)
			$msg = "duplicated!";
		else
			$msg = "insert failed.";
			
		$smarty = $_SESSION['smarty'];		
		$smarty->assign("msg", $msg);
		$content = $smarty->fetch("employees/employees_insertResult.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
		
	}
	
	function inactiveAction(){
		$emp_id = $_REQUEST['args'];
		$employees_obj = new employees();
		$result = $employees_obj->inactivateAEmployee($emp_id);
		if ($result == 1)
			$msg = "inactivate successfully";		
		else
			$msg = "inactivate failed.";
			
		$smarty = $_SESSION['smarty'];		
		
		
		$list_employees_box = $this->getListEmployeeBox();
		$smarty->assign("list_employees_box",$list_employees_box);
		$smarty->assign("msg", $msg);
		
		$content = $smarty->fetch("employees/employees.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
	
	function activeAction(){
		$emp_id = $_REQUEST['args'];
		$employees_obj = new employees();
		$result = $employees_obj->activateAEmployee($emp_id);
		if ($result == 1)
			$msg = "activate successfully";		
		else
			$msg = "activate failed.";
			
		$smarty = $_SESSION['smarty'];		
		
		
		$list_employees_box = $this->getListEmployeeBox();
		$smarty->assign("list_employees_box",$list_employees_box);
		$smarty->assign("msg", $msg);
		
		$content = $smarty->fetch("employees/employees.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
	
	function insertFormAction(){
		$smarty = $_SESSION['smarty'];		
		
		$insertform_employees_box = $smarty->fetch("employees/employees_insert_form.html");
		$smarty->assign("insertform_employees_box",$insertform_employees_box);
		
		$content = $smarty->fetch("employees/employees.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");
	}
	
	function editFormAction(){
		$emp_id 			= $_REQUEST['args'];
		$smarty 			= $_SESSION['smarty'];		
		
		$employees_obj 		= new employees();
		$current_data 		= array();
		$current_data 		= $employees_obj->getEmployeesInfo($emp_id);
		
		$smarty->assign("current_data", $current_data);
		
		$editform_employees_box = $smarty->fetch("employees/employees_edit_form.html");
		$smarty->assign("editform_employees_box",$editform_employees_box);
		
		$content = $smarty->fetch("employees/employees.html");		
		$smarty->assign("content", $content);
		
		$smarty->display("homepage.html");
		
	}
	
	function editAction(){
		$employees_obj = new employees();
		$data 			= array();
		
		$data['emp_id'] 		= $_REQUEST['emp_id'];
		$data['emp_name'] 		= $_REQUEST['emp_name'];
		$data['emp_password'] 	= $_REQUEST['emp_password'];
		$data['emp_address'] 	= $_REQUEST['emp_address'];
		$data['emp_phone'] 		= $_REQUEST['emp_phone'];
		
		
		$result = $employees_obj->editACustomer($data);
		
		if ($result == 1)
			$msg = "edit successfully";
		else if ($result == -1)
			$msg = "duplicated!";
		else
			$msg = "update failed.";
			
		$smarty = $_SESSION['smarty'];		
		$smarty->assign("msg", $msg);
		$content = $smarty->fetch("employees/employees_updateResult.html");		
		$smarty->assign("content", $content);		
		$smarty->display("homepage.html");
	}
	
}
?>